<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 1.通过URLSearchParams()
    let urlSearchParams = new URLSearchParams(window.location.search)
    for (let [key, value] of urlSearchParams.entries()) {
      console.log(key, value);
    }
    console.log(urlSearchParams)


    // 2.通过split
    function url2Obj(url) {
      // ?name=zhansan&age=12
      let urlParams = url.split('?')[1]
      // ['name=zhansan', 'age=12']
      let arrParams = urlParams.split('&')
      let params = {}
      arrParams.forEach((param, index) => {
        let key = param.split('=')[0]
        let value = param.split('=')[1]
        params[key] = value
      })
      return params
    }

    console.log(url2Obj('http://www.meituan.com?name=soulkey&age=24'));

  </script>
</body>

</html>